package edu.hhu.wifispark;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;

import edu.hhu.wifispark.entry.BasePhone;
import edu.hhu.wifispark.entry.Caclu;
import edu.hhu.wifispark.entry.Customer;
import edu.hhu.wifispark.entry.Customerflow;
import edu.hhu.wifispark.entry.Customerlive;
import edu.hhu.wifispark.entry.Record;

public class DBConnect {
	DruidPlugin dp = null;
	ActiveRecordPlugin arp = null;
//	String url="jdbc:mysql://115.159.212.210:3306/wifi?rewriteBatchedStatements=true";
	String url="jdbc:mysql://10.196.83.60:3306/wifi?rewriteBatchedStatements=true";
//	String url="jdbc:mysql://192.168.117.134:3306/wifi?rewriteBatchedStatements=true";
	String user="root";
	String pass="root";
	
	public void connect(){
//		PropKit.use(new File("db.properties"));
		dp = new DruidPlugin(url,user,pass);
		dp.start();
		arp = new ActiveRecordPlugin(dp);
		arp.addMapping("basephone", "mac,atime",BasePhone.class);
		arp.addMapping("customer", "mac,atime",Customer.class);
		arp.addMapping("record", "mac,entertime",Record.class);
		arp.addMapping("customerflow", "atime",Customerflow.class);
		arp.addMapping("customerlive", "mac",Customerlive.class);
		arp.addMapping("caclu", "id",Caclu.class);
		arp.start();
	}
	
	public void close(){
		dp.stop();
		arp.stop();
	}
}
